package edu.pku.sei.modeler.neditor.part;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.EditPolicy;

import edu.pku.notation.runtime.constance.ColorConstance;
import edu.pku.sei.modeler.model.notation.shape.Shape;
import edu.pku.sei.modeler.neditor.part.policy.NodeContainerLayoutEditPolicy;
import edu.pku.sei.modeler.neditor.part.policy.NodeDeleteEditPolicy;

public class EllipseEditPart extends AbstractMetaElementPart {
	protected IFigure createFigure() {
		IFigure figure = null;
		edu.pku.sei.modeler.model.notation.shape.Ellipse model = (edu.pku.sei.modeler.model.notation.shape.Ellipse)getModel();
		
		switch(model.getType()){
		case edu.pku.sei.modeler.model.notation.shape.Ellipse.ELLIPSE:
			figure = new edu.pku.notation.runtime.draw2d.EllipseFigure();
			break;
		case edu.pku.sei.modeler.model.notation.shape.Ellipse.CIRCLE:
			figure = new edu.pku.notation.runtime.draw2d.CircleFigure();
			break;
		}
		figure.setLayoutManager(new XYLayout());
		
		return figure;
	}
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE,new NodeContainerLayoutEditPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE,new NodeDeleteEditPolicy());
	}
	
	protected List getModelChildren() {
		return ((Shape)getModel()).getSlaves();
	}

	@Override
	protected void refreshVisuals() {
		org.eclipse.draw2d.Shape figure = (org.eclipse.draw2d.Shape)getFigure();
		edu.pku.sei.modeler.model.notation.shape.Ellipse model = (edu.pku.sei.modeler.model.notation.shape.Ellipse)getModel();
		figure.setBounds(model.getBound());	
		figure.setForegroundColor(ColorConstance.BLACK);
		figure.setBackgroundColor(ColorConstance.WHITE);
		
		model.doLayout();
	}
}
